package com.service.other;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * 将Gps数据写入指定文件中
 * @author sxc
 *
 */
public class Writer {
	/**
	 * 将数据写入指定文件中
	 * @param path
	 * @param content
	 */
	public static void append(String path, String content) {   
        RandomAccessFile randomFile = null;  
        try {
        	File file = new File(path);
        	File folder = new File(file.getParent());
        	if(!folder.exists()){
        		folder.mkdirs();
        	}
            if(!file.exists()){  
            	file.createNewFile();
            }
            randomFile = new RandomAccessFile(path, "rw");        
            long fileLength = randomFile.length();         
            randomFile.seek(fileLength);
            randomFile.write(content.getBytes());
            randomFile.write("\r\n".getBytes()); 
        } catch (IOException e) {     
            e.printStackTrace();     
        } finally{  
            if(randomFile != null){  
                try {  
                    randomFile.close();  
                } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
    }    
}
